Now let's start adding some code to our shop.
And I'm going to start on the client side here, the gooey side.
Let's go to starter GUI screen GUI shop frame, and then here's our shop script.
Let's open that up.
I want to add two variables to this script.
We're not quite at the top.
That's the top.
That's line one.
Let's go and look at about line ten.
We have some variables for the selected item, right?
So if you have cabin or fence, you have the image, the name, the price.
But we need to add the type, whether it's a house type or a fence type.
So I'll do local preview type equals shop frame to by frame.
What was that like?
Property.
There it is, property type label.
There we go.
And we're going to need another variable.
I'm going to put it at the bottom.
And this is for the player data.
Whoops, we'll call it player data.
We're going to initialize it to nil When we open the shop.
It's going to be server side.
We're going to send a remote event.
Player data is going to get the data for the player about the property it owns.
So we don't accidentally sell them a house when he doesn't own a lot or sell them the same house twice.
We don't want to do that.
So in the preview item, when we select an item on the right, it's going to show the values of that
item.
Let's add our preview type stuff and it's going to be of type text on the button.
We are going to have.
Let's take a look.
Items frame.
Here's a button.
So we have two buttons.
Prop type.
So it's going to be a prop type and that's a string value.
So it'll be prop type value, prop type dot value, and then we'll know whether it's a house or a fence.
Also, we have preview item, we have clear fields.
So something happens where we got to clear the fields out like they make a purchase or they close the
window, things like that.
Let's do a control C, control V, and I'm just going to call this instead of preview price preview
prop type.
Another thing we're going to look at is.
Our shop.
Re right.
This is how we open our window up.
A server event happens and it says, Hey, open up the GUI for the player.
But since we're on the server side coming to the client side, we can send our property data.
I'm just going to call that data.
We haven't done it yet.
That's going to be over on server side, but we will.
And then I'm going to get my player data variable player data variable, set it equal to the data that
came over from the remote event from the server side.
And we want to do a little bit of error checking to.
So notice how we did this is owned.
We check to see if the player had the item, whether it was in the backpack or they're holding it.
I'm going to change this.
I'm going to change this to can buy.
Let's also add a prop type here in the parameters right after item.
I'm going to say prop type.
We're not going to check the character.
Right.
Because it's not a tool.
And what should we do here?
We don't need to check to see if the item is owned that way either.
Well, we do need to do is check if not player data.
So if there's no player data or not player data dot has lot, then let's grab this line Control C,
we're going to give them a message.
This shows up on top of the shop frame.
Let's leave a message that makes more sense.
Let's say player does not have a lot exclamation mark and then we're going to return False.
They cannot buy a lot.
They either had they had no data or they didn't have a lot.
I'm going to get rid of this.
And now I have to look at our type.
So we got down to the point where we do have a lot.
We're going to say if prop type equals equals, and I'm going to hardcode these, I'm going to use string
literals.
You might want to have a list of of proper prop types that you can draw from some enum, but I didn't
really cover that in this class, so we'll just type in fence.
So if it's a prop type fence, if not player data dot fence, then print.
We can buy a fence.
All right.
So if we hold on, let me just finish this return.
True.
So if the prop type that we're purchasing is of type fence, we're going to check to see if they have
a fence.
If they don't have a fence, if not fence, we can buy a fence.
So we're going to return.
True.
We're going to say can buy is true.
We don't need to leave a message on the on the shop because it made sense.
Everything was fine.
I'm going to do another if statement here.
I probably should have just done an if else but I'll do an if statement.
If player data dot fence equals equals the item, let's let them know that they already owned the item,
we're going to cancel the purchase.
So I'm going to say message label dot text equals already owns that item, exclamation.
And then I'm just going to return a false Don't buy it.
Well, we can't buy it, right?
We're going to return a false.
Let's go ahead and copy this for the House Control C and we'll go down one line, Control V, Let's
change all this fence stuff to house stuff.
So if the property type is of type house, check to see if there's house data.
If there's not house data, we can definitely buy a house.
Well, we're also going to check for money, but we're going to do that server side.
These are preliminary checks.
So this is true.
It's going to say, All right, we're going to go to server side.
We need to change this to check for player data house.
If the house is the item that we're trying to buy up, already owns that item.
So we don't have to change anything here.
We're going to deny them.
And let's take a look down here where we're getting this nasty red line.
We have an error is owned.
We don't want is owned, we want can buy and we don't want it to be not is owned.
We want it to be just can buy.
Another thing, we're going to send the prop type, so we'll do the preview type, which is the prop
type text into can own because we've got to check to see if it's house or fence.
Here we're checking to see if we have enough points, but we're doing the subtracting on the server
side.
So now we'll get down here to shop and we need to send the property type, right?
So we have that in preview type dot text.
So we make two lines for this.
Yeah.
Let's go ahead.
You can leave it all on one, but I want you to be able to see it.
All right.
That looks pretty good.
Let's check this out.
We're not getting any lot data yet from the server up to our UI, but we can still check for errors.
Let's go to the view output window.
Oh, and we still have our property test script putting houses out there.
We're going to have to disable that, although it does look kind of cool.
Let's go to our owner.
Hit the little bell.
Dang.
And this should say player does not have lot because we don't have the lot information on the client.
I'm going to hit my cabin and hit play or by boom player does not have lot and there's no red nasty
red down there so it doesn't look like we have any errors so far.
Let's hit this again.
Let's hit fence.
By player does not have lot.
All right.
That's looking pretty good.